package activiti;

import org.activiti.engine.*;
import org.activiti.engine.task.Task;

import java.util.List;

public class FourthTest {

    public static void main(String[] args) throws Exception {
        // 创建流程引擎
        ProcessEngineConfiguration pe=
                ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault()
                        .setProcessEngineName("testEngineName");
        ProcessEngine engine=pe.buildProcessEngine();
        ProcessEngines.registerProcessEngine(engine);
        // 得到流程存储服务组件
        RepositoryService repositoryService = engine.getRepositoryService();
        // 得到运行时服务组件
        RuntimeService runtimeService = engine.getRuntimeService();
        // 获取流程任务组件
        TaskService ts = engine.getTaskService();
        // 部署流程文件
        repositoryService.createDeployment().addClasspathResource("bpmn/FourProcess.bpmn").deploy();
        // 启动流程
        runtimeService.startProcessInstanceByKey("fourProcess");
        // 集合任务查询
        List<Task> tasks = ts.createTaskQuery().list();
        for (Task userTask:tasks) {
            System.out.println("当前任务完成前，任务数为" + tasks.size() + "个");
            ts.complete(userTask.getId());
            Thread.sleep(5000);

            tasks = ts.createTaskQuery().list();
            System.out.println("当前任务完成后，任务数为" + tasks.size());
        }
    }
}
